package com.vanzo.talkie;

import android.view.View;
import android.widget.CompoundButton;
import android.widget.Switch;
import android.widget.TextView;

/**
 * Created by tisen on 2018/1/23.
 */

public class ModeSwitch implements CompoundButton.OnCheckedChangeListener {
    private TextView textView;
    private Switch aSwitch;
    private int falseStringId;
    private int trueStringId;

    public ModeSwitch(TextView textView, Switch aSwitch, int falseStringId, int trueStringId, boolean isChecked) {
        this.textView = textView;
        this.aSwitch = aSwitch;
        this.falseStringId = falseStringId;
        this.trueStringId = trueStringId;
        setChecked(isChecked);
        this.aSwitch.setOnCheckedChangeListener(this);
    }

    public void setChecked(boolean isChecked) {
        this.textView.setText(isChecked ? trueStringId : falseStringId);
        this.aSwitch.setChecked(isChecked);
    }

    @Override
    public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
        this.textView.setText(isChecked ? trueStringId : falseStringId);
    }

    public void setVisibility(int visibility) {
        textView.setVisibility(visibility);
        aSwitch.setVisibility(visibility);
    }
}
